package com.joven.shelltest.controller;

import com.joven.shelltest.utils.ExportWordUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalDate;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author: wzj
 * @Date: 2024/3/26 17:32
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/boy")
public class UtilController {

    @GetMapping("/doc")
    public String testShell(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> params = new HashMap<>(16);
        //模板路径
        String templatePath = "template/testDoc.docx";
        params.put("enterName", "浙江连成环保科技有限公司");
        params.put("unitCreditNum", "123456");
        params.put("reason", "学习");
        params.put("date", LocalDate.now());
        params.put("operator", "joven");
        params.put("address", "婺城区孟家塘");
        params.put("regDate", LocalDate.now());
        params.put("regType", "工本");
        params.put("indate", LocalDate.now());
        params.put("status", "营业中");
        params.put("regNum", "1000000");
        params.put("regNo", "ZJQZ1234546");
        Long time = System.currentTimeMillis();
        // 生成的word格式
        String formatSuffix = ".docx";
        // 拼接后的文件名
        String fileName = time + formatSuffix;
        //导出word
        ExportWordUtils.exportWord(templatePath, fileName, params, request, response);
        return "Hello doc => " + fileName;
    }
}
